package cn.zh.npro.Adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import cn.zh.npro.Activity.RepOd;
import cn.zh.npro.Item.CfItem;
import cn.zh.npro.MyApplication;
import cn.zh.npro.R;

/**
 * Created by WYN on 2018/3/5 0005.
 */

public class CfAdapter extends BaseAdapter {
    Context context;
    ArrayList<CfItem> arrayList;
    LayoutInflater inflater;
    MyApplication mapp;
    public CfAdapter(Context context,ArrayList<CfItem> arrayList,MyApplication mapp){
        this.context=context;
        this.arrayList=arrayList;
        this.mapp=mapp;
        inflater=LayoutInflater.from(context);
        }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (null==view){
            view=inflater.inflate(R.layout.cfi_layout,null,false);
            holder=new Holder();
            holder.cfname=view.findViewById(R.id.cfname);
            holder.cftype=view.findViewById(R.id.cftype);
            holder.cfadre=view.findViewById(R.id.cfadre);
            holder.repod=view.findViewById(R.id.repod);
            view.setTag(holder);
           }else {
            holder= (Holder) view.getTag();
           }
          holder.cfname.setText(arrayList.get(i).getCompanyName());
        if (arrayList.get(i).getCustomerLevel().equals("null")){
            holder.cftype.setText("空");
        }else {
            holder.cftype.setText(arrayList.get(i).getCustomerLevel());
           }
          if (arrayList.get(i).getAddress().equals("null")){
              holder.cfadre.setText("");
          }else {
              holder.cfadre.setText(arrayList.get(i).getAddress());
            }
          holder.repod.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  mapp.setClID(arrayList.get(i).getId());
                  Intent intent=new Intent(context,RepOd.class);
                  intent.putExtra("type","0");
                  intent.putExtra("customerID",arrayList.get(i).getId());
                  context.startActivity(intent);
              }
          });
          return view;
        }

    public class Holder{
        TextView cfname,cftype,cfadre,repod;

    }


}
